package com.gr3g.dev.draw;

import java.awt.BorderLayout;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;

/** Hello world! */
public class App extends JFrame {

    /** Numéro de série. */
    private static final long serialVersionUID = 8622944357134761695L;

    private final PanelDraw panel;
    private final TreeDraw tree;

    /** Constructeur. */
    public App() {
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setSize(800, 500);

        final JLabel posX = new JLabel("0");
        final JLabel posY = new JLabel("0");

        final JPanel bottom = new JPanel();
        bottom.add(new JLabel("X: "));
        bottom.add(posX);
        bottom.add(new JLabel("Y: "));
        bottom.add(posY);
        this.add(bottom, BorderLayout.SOUTH);

        this.tree = new TreeDraw();

        this.panel = new PanelDraw(this.tree, posX, posY);
        this.add(this.panel, BorderLayout.CENTER);

        this.tree.setActionAddCircle(this.panel.addCircle);
        this.tree.setActionAddArc(this.panel.addArc);
        this.tree.setActionAddMultiLine(this.panel.addLine);
        this.tree.setActionDelete(this.panel.deleteEtape);
        this.tree.setActionExporter(this.panel.exporter);
        this.tree.setActionEdit(this.panel.editer);
        this.tree.setActionOpen(this.panel.openJSON);
        this.tree.events();

        this.tree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode(
                this.panel.getModele())));

        this.add(this.tree, BorderLayout.WEST);
    }

    /** Launcher.
     * @param args Arguments */
    public static void main(final String[] args) {
        new App().setVisible(true);
    }

}
